package astoliarskyi.wicket.card.restriction;

import astoliarskyi.wicket.card.restriction.Term;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class MonthlyTerm extends Term {

	private final Calendar validityMonthAndYear;

	public MonthlyTerm(Calendar monthAndYear) {
		super(Term.TermType.MONTHLY);
		validityMonthAndYear = new GregorianCalendar();
		validityMonthAndYear.set(Calendar.DAY_OF_MONTH, 1);
		validityMonthAndYear.set(Calendar.MONTH, monthAndYear.get(Calendar.MONTH));
		validityMonthAndYear.set(Calendar.YEAR, monthAndYear.get(Calendar.YEAR));
	}
	
	@Override
	public boolean checkout(Calendar dateToday) {
		boolean isValid = 
			dateToday.get(Calendar.MONTH) == validityMonthAndYear.get(Calendar.MONTH) &&
			dateToday.get(Calendar.YEAR) == validityMonthAndYear.get(Calendar.YEAR);
		return isValid;
	}

	@Override
	public Calendar getValidityTerm() {
		Calendar toReturn = (Calendar) validityMonthAndYear.clone();
		return toReturn;
	}


}
